//
//  TableDetailVC.m
//  22-AliPlanet_HomeWork
//
//  Created by 曹曹 on 16/8/15.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "TableDetailVC.h"
#import "TableDetailPlayCell.h"
#import "TableDetailCell.h"
#import "TableDetailFollowCell.h"
#import "DetailModel.h"
#import "DetailData.h"
#import "DetailSonglist.h"

@interface TableDetailVC () <UITableViewDelegate, UITableViewDataSource>

@end

@implementation TableDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)setDetailModel:(DetailModel *)detailModel {
    NSLog(@"%@", detailModel);
    _detailModel = detailModel;
    [_tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _detailModel.data.songList.count + 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        TableDetailPlayCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detailplaycell"];
        cell.songlist = _detailModel.data.songList;
        return cell;
    } else if ( indexPath.row == _detailModel.data.songList.count + 1) {
        TableDetailFollowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"followcell"];
        return cell;
    } else {
        TableDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detailcell"];
        cell.index = indexPath.row;
        cell.songlist = _detailModel.data.songList[indexPath.row -1];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
